﻿function AzureOnlineTablesView(context) {

    var self = this;

    var screen = ko.observable('');

    var tablesView = new AzureOnlineTablesListView(context);
    var recordsListView = new AzureOnlineTableRecordsListView(context);
    var recordView = new AzureOnlineTableRecordViewModel(context);
    var deleteRecordDetails = new AzureOnlineTableRecordDeleteDetailsView(context);
    var deleteDetails = new AzureOnlineTableDeleteView(context);
    var tableSettingsDetails = new AzureOnlineTableSettingsView(context);
    var queryBuilder = new AzureOnlineTableRequestBuilder(context);

    var spaRuntime = context.spaRuntime;

    var tablesRoute = spaRuntime.findRouteByName('tables').addExecute(function (ev, args, phash) {
        screen('tables');
    });

    var recordsRoute = spaRuntime.findRouteByName('tableRecords').addExecute(function (ev, args, phash) {
        screen('records');
    });

    context.api.subscribe(function () {
        if (spaRuntime.getCurrentRoute() == recordsRoute) {
            tablesRoute.navigateHash({});
        }
    });

    recordView.addOnSuccess(function () {
        recordsListView.reload();
    });

    self.tablesView = tablesView;
    self.recordsListView = recordsListView;
    self.recordView = recordView;
    self.deleteRecordDetails = deleteRecordDetails;
    self.deleteDetails = deleteDetails;
    self.tableSettingsDetails = tableSettingsDetails;
    self.queryBuilder = queryBuilder;
    self.screen = screen;
    self.context = context;
}
